import { getFileSuffix } from '@web-utils/core'

/**
 * 获取文件图标
 * @param row
 * @returns {string}
 */
export function getFileIcon(row) {
  const fileType = row.type === 'directory' ? 'directory' : row.format || row.type
  if (/jpg|jpeg|png|gif|bmp|webp/i.test(fileType)) {
    return require('@/assets/images/file-type-icon/24/Picture_24.png')
  } else if (/doc|docx/i.test(fileType)) {
    return require('@/assets/images/file-type-icon/24/Word_24.png')
  } else if (/ppt|pptx/i.test(fileType)) {
    return require('@/assets/images/file-type-icon/24/PPT_24.png')
  } else if (/txt/i.test(fileType)) {
    return require('@/assets/images/file-type-icon/24/Text_24.png')
  } else if (/pdf/i.test(fileType)) {
    return require('@/assets/images/file-type-icon/24/PDF_24.png')
  } else if (/xls|xlsx/i.test(fileType)) {
    return require('@/assets/images/file-type-icon/24/Xls_24.png')
  } else if (/zip|rar|tar|gzip/i.test(fileType)) {
    return require('@/assets/images/file-type-icon/24/Zip_24.png')
  } else if (/folderWork/i.test(fileType)) {
    return require('@/assets/images/file-type-icon/24/Folder_24_coopetition.png')
  } else if (/directory/i.test(fileType)) {
    return require('@/assets/images/file-type-icon/24/Folder_24.png')
  } else if (/exe/i.test(fileType)) {
    return require('@/assets/images/file-type-icon/24/Exe_24.png')
  } else if (/link/i.test(fileType)) {
    return require('@/assets/images/file-type-icon/24/blue_link_24.png')
  } else if (/wj/i.test(fileType)) {
    return require('@/assets/images/file-type-icon/24/Wj_24.png')
  } else if (/sj/i.test(fileType)) {
    return require('@/assets/images/file-type-icon/24/Sj_24.png')
  } else if (/departments/i.test(fileType)) {
    return require('@/assets/images/file-type-icon/24/departments_24.png')
  } else if (/personal/i.test(fileType)) {
    return require('@/assets/images/file-type-icon/24/personal_24.png')
  } else {
    return require('@/assets/images/file-type-icon/24/File_24.png')
  }
}

/**
 * 通过文件名获取文件图标
 * @param fileName 文件名,必须包含后缀
 * @returns {string}
 */
export function getFileIconBySuffix(fileName) {
  return getFileIcon(getFileSuffix(fileName))
}
